#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF=0x3f;
const int N=310;
int n;

int edge[N][N];
int dist[N];
int st[N];
int prim()
{
	memset(dist,INF,sizeof(dist));
	int ret=0;
	dist[0]=0;
	for(int i=0;i<=n;i++)
	{
		int t=-1;
		for(int j=0;j<=n;j++)
		{
			if(!st[j] && (t==-1 ||dist[t]>dist[j]))
			{
				t=j;
			}	
		}
		st[t]=1;
		ret+=dist[t];
		for(int j=0;j<=n;j++)
		{
			dist[j]=min(dist[j],edge[t][j]);
		}
	}
	return ret;
}
int main()
{
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{
		cin>>edge[0][i];
		edge[i][0]=edge[0][i];
	}
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>edge[i][j];
			edge[j][i]=edge[i][j];
		}
	}
	
	cout<<prim()<<endl;
	return 0;
}
